package com.itheima.springboottlias.controller;


import Pojo.Emp;
import Pojo.LogInfor;
import Pojo.Result;
import com.itheima.springboottlias.service.impl.EmpServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpServiceImpl empService;
    //登录
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        //接收参数为json格式（使用@RequestBody+实体对象）
        log.info("登录");
//        Emp empResult =  empService.checkLogin(emp);

//        Map map=new HashMap<>();
//        map.put("id",empResult.getId());
//        map.put("username",empResult.getUsername());
//        map.put("name",empResult.getName());
        LogInfor empResult =  empService.checkLogin(emp);

        if(empResult==null){
            return Result.error("用户名或密码错误");
        }

        return Result.success(empResult);
    }
}
